package cn.fl.riskctrl.acard.controller;

import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.riskctrl.acard.service.IAcardService;
import com.alibaba.fastjson.JSONObject;
import fl.riskctrl.facade.riskctrl.dto.DataResultDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Description: 百融-征信记录

 控制层
 */
@Controller
@RequestMapping("/riskctrl/acard")
public class AcardCreditReportController extends BaseController{
	private static final Logger logger = LoggerFactory.getLogger(AcardCreditReportController.class);
	/**
	 *
	 */
	@Autowired
	private IAcardService acardSearchService;
	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toAcardIframePage.do", method = { RequestMethod.GET })
	public ModelAndView toXjdbIframePage(HttpServletRequest request, HttpServletResponse response) {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "toListPage", " 到列表页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		ModelAndView view = new ModelAndView("riskctrl/acard/acardIframe");
		String prjId = request.getParameter("prjId");//项目ID
		view.addObject("prjId", prjId);
		BaseLogUtils.info(logger, "toAcardframePage", "跳转到列表页面.", CurrentThreadContext.getCurrentUserName());
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "toListPage", " 到列表页面.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 初始化A卡模型数据
	 */
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public DataResultDTO initList(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "initList", " 初始化A卡模型数据.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		String prjId = request.getParameter("prjId");
		DataResultDTO result = new DataResultDTO(BaseConstant.IS_YESNO_NO, "");
		try {
			result = this.acardSearchService.reCalculateAcard(Long.valueOf(prjId));
			result.setSuccess(BaseConstant.IS_YESNO_YES);
			Long endTm = System.currentTimeMillis();
			BaseLogUtils.info(logger, "initList", " 初始化A卡模型数据.耗时：" + (endTm - startTm));
		} catch (BaseException e) {
			result.setInfo(e.getMessage());
			BaseLogUtils.error(logger, "initList", "初始化A卡数据失败!" ,e);
		} catch (Exception e) {
			result.setInfo(e.getMessage());
			BaseLogUtils.error(logger, "initList", "初始化A卡数据失败!", e);
		}
        BaseLogUtils.info(logger, "initList", " 初始化A卡模型数据.结果result="+ JSONObject.toJSONString(result));
        return result;
	}

	/**
	 * 重新计算A卡模型
	 */
	@RequestMapping(value = "/calculateAcard.do", method = { RequestMethod.GET})
	@ResponseBody
	public DataResultDTO calculateAcard(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "calculateAcard", " 重新计算A卡模型.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		String prjId = request.getParameter("prjId");
		String type = request.getParameter("type");
		DataResultDTO result=new DataResultDTO(BaseConstant.IS_YESNO_NO,"");
		try{
			result=this.acardSearchService.reCalculateAcard(Long.valueOf(prjId));
			Long endTm = System.currentTimeMillis();
			BaseLogUtils.info(logger, "calculateAcard", " 重新计算A卡模型.耗时：" + (endTm-startTm));
		}catch(BaseException e){
			result.setInfo(e.getMessage());
			BaseLogUtils.error(logger, "calculateAcard", "重新计算A卡模型失败!",e);
		}catch(Exception e){
			result.setInfo(e.getMessage());
			BaseLogUtils.error(logger, "calculateAcard", "重新计算A卡模型失败!",e);
		}
        BaseLogUtils.info(logger, "initList", " 计算A卡模型数据.结果result="+ JSONObject.toJSONString(result));
        return result;
    }

	/**
	 * 重新计算A卡模型
	 */
	@RequestMapping(value = "/calculateYsAcard.do", method = { RequestMethod.GET})
	@ResponseBody
	public DataResultDTO calculateYsAcard(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "calculateAcard", " 重新计算A卡模型.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		String prjId = request.getParameter("prjId");
		String rcCstBscInfoId = request.getParameter("rcCstBscInfoId");
		DataResultDTO result=new DataResultDTO(BaseConstant.IS_YESNO_NO,"");
		try{
			result=this.acardSearchService.reCalculateYsAcard(Long.valueOf(prjId),Long.valueOf(rcCstBscInfoId));
			Long endTm = System.currentTimeMillis();
			BaseLogUtils.info(logger, "calculateAcard", " 重新计算A卡模型.耗时：" + (endTm-startTm));
		}catch(BaseException e){
			result.setInfo(e.getMessage());
			BaseLogUtils.error(logger, "calculateAcard", "重新计算A卡模型失败!",e);
		}catch(Exception e){
			result.setInfo(e.getMessage());
			BaseLogUtils.error(logger, "calculateAcard", "重新计算A卡模型失败!",e);
		}
		BaseLogUtils.info(logger, "initList", " 计算A卡模型数据.结果result="+ JSONObject.toJSONString(result));
		return result;
	}
}


